"""
面试题解析
"""


def judge(pattern, string):
    words = string.split()
    if len(pattern) != len(words):
        return False
    temp, values = {}, set()
    for index, ch in enumerate(pattern):
        if ch not in temp:
            if words[index] in values:
                return False
            temp[ch] = words[index]
            values.add(words[index])
        elif temp[ch] != words[index]:
            return False
    return True


print(judge('abaa', 'apple orange apple apple'))
print(judge('aaaa', 'apple orange orange apple'))
print(judge('aaba', 'apple apple apple apple'))
